import { tableConfig } from "./table";
import { searchConfig } from "./search";
import { queryParams } from "./store";
export default defineComponent({
  props: {
    party_id: {
      type: Number,
      default: void 0,
    },
  },
  setup(props, { attrs, emit, expose, slots }) {
    const handleAction = ({ record, type, callback }: any) => {};
    const refreshTable = async (searchParams: any = {}) => {
      defineTable.pagination.current = 1;
      initObjAttr(queryParams, searchParams);
      await fetchList();
    };
    const fetchList = async () => {
      const { loading, pagination, dataSource } = defineTable;
      try {
        const join_start_time = queryParams?.["join_start_end"]?.[0]
          ? $dayjs(queryParams?.["join_start_end"]?.[0]).format("YYYY-MM-DD")
          : void 0;
        const join_end_time = queryParams?.["join_start_end"]?.[1]
          ? $dayjs(queryParams?.["join_start_end"]?.[1]).format("YYYY-MM-DD")
          : void 0;

        const signed_start_time = queryParams?.["signed_start_end"]?.[0]
          ? $dayjs(queryParams?.["signed_start_end"]?.[0]).format("YYYY-MM-DD")
          : void 0;
        const signed_end_time = queryParams?.["signed_start_end"]?.[1]
          ? $dayjs(queryParams?.["signed_start_end"]?.[1]).format("YYYY-MM-DD")
          : void 0;
        loading.value = true;
        dataSource.value = [];
        const res: any = await societyApi.party.queryMemberList({
          page: pagination.current,
          page_size: pagination.pageSize,
          party_id: props.party_id,
          initiator: queryParams.initiator,
          gender: queryParams.party_id,
          role: queryParams.role,
          join_start_time,
          join_end_time,
          sign_status: queryParams.sign_status,
          signed_start_time,
          signed_end_time,
        });
        if (res.code != 200) return message.error(res.message);
        dataSource.value = res?.data?.returnList ?? [];
        pagination.total = res?.data?.attributes?.total ?? 0;
      } catch (error: any) {
        message.error(error.message);
      } finally {
        loading.value = false;
      }
    };

    const defineSearch = searchConfig({ handleAction, refreshTable });
    const defineTable = tableConfig({ handleAction, fetchList });
    // onActivated(() => {
    fetchList();
    // });

    return () => (
      <>
        <s-design defineTable={defineTable} defineSearch={defineSearch} />
      </>
    );
  },
});
